package edu.servletcontext;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 获取上下文路径
 * getContextPath();
 */
@WebServlet("/servletContext03")
public class ServletContextDemo03 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //通过ServletContext对象获取上下文路径
        ServletContext servletContext = this.getServletConfig().getServletContext();
        System.out.println("ServletContext：" + servletContext.getContextPath());

        //通过request获取上下文路径
        System.out.println("request：" + request.getContextPath());
    }
}
